import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_base/generated/assets.dart';
import 'package:flutter_base/widgets/image/auto_image.dart';

enum EnumEmptyType {
  big, //图片160
  middle, //图片120
  small //图片80
}

class EmptyView extends StatelessWidget {
  const EmptyView({
    super.key,
    this.image,
    this.message,
    this.type = EnumEmptyType.big,
    this.textColor,
  });

  final String? image;
  final String? message;
  final EnumEmptyType type;
  final Color? textColor;

  @override
  Widget build(BuildContext context) {
    double imageSize = 0.0;
    double vertical = 0.0;
    switch (type) {
      case EnumEmptyType.middle:
        {
          imageSize = 120.w;
          vertical = 40.w;
        }
      case EnumEmptyType.small:
        {
          imageSize = 80.w;
          vertical = 12.w;
        }
      default:
        {
          // vertical = 160.w;
          imageSize = 160.w;
        }
    }
    return Center(
      child: SingleChildScrollView(
        physics: const NeverScrollableScrollPhysics(),
        child: Container(
          padding: EdgeInsets.symmetric(vertical: vertical),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(
                width: imageSize,
                height: imageSize,
                child: AutoImage(
                  image ?? Assets.emptyNoData,
                  fit: BoxFit.cover,
                ),
              ),
              Text(
                message ?? "暂无数据",
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: textColor ?? Colors.black.withOpacity(0.5),
                  fontSize: 12,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  factory EmptyView.networkView({String? message, EnumEmptyType? type}) {
    return EmptyView(
      image: Assets.emptyNoNetwork,
      type: type ?? EnumEmptyType.big,
      message: message ?? "网络异常",
    );
  }
}
